﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using TTGame;

/*
 * PuppetBehaviourHelper
 * 扩展puppet更丰富的动作。技能编辑器会用到各种人物动作。
 *
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/21/2017 9:04:03 AM
 */
namespace TTGameEngine {

[System.Serializable]
public class SkillAudioEffect {
    public string audioName = string.Empty;
    public float delay = 0f;
    public bool isLoop = false;
    [HideInInspector]
    public float curDelay = 0f;

    public void Reset() {
        curDelay = delay;
    }
}
public enum LookSkillSyn {
    None,
    LookSyn,
    MoveSyn
}

/// <summary>
/// 播放人物动画所需要的参数
/// 仅包含播放一次动画用到的参数，不包含其他技能参数。
/// 其他技能参数找SkillTL。
/// </summary>
// 如果设置成serializable，则属性无法设置成null，会被Editor实例化。
// [System.Serializable]
public class SkillAnimInfo {
    public string animation;
    public float animTime;
    public bool animSyn = true;
    public bool isLoop = false; //保持循环，相当于引导施法或者持续射击动作，直到外部操作取消该标志。
    //朝向同步选项，同步于移动方向或者同步于面向方向（即摇杆）
    public LookSkillSyn lookSyn = LookSkillSyn.None;
    public float t_animTime = 0f;

    public SkillAnimInfo Init(string animName, float time, bool aAnimsyn, LookSkillSyn aLooksyn, bool aIsLoop) {
        animation = animName;
        animTime = time;
        animSyn = aAnimsyn;
        lookSyn = aLooksyn;
        isLoop = aIsLoop;
        return this;
    }
    public void Reset() {
        t_animTime = 0f;
    }

    public void BreakLoop(bool skipCurAnim) {
        isLoop = false;
        if(skipCurAnim) {
            t_animTime = animTime;
        }
    }

    public string Dump() {
        return string.Format("anim:[{0}] isLoop:[{1}]", animation, isLoop);
    }

}

public static class PuppetBehaviourHelper {



    public static bool IsPuppetLookAtPos(this Puppet obj, Vector3 pos) {
        return IsPuppetLookAtDir(obj, (pos - obj.objTF.forward).normalized);
    }

    public static bool IsPuppetLookAtDir(this Puppet obj, Vector3 dir) {
        if(Tools.Vector3Equals2D(obj.objTF.forward, dir)) {
            return true;
        }
        return false;
    }


}

}
